package com.top4create.model;

import com.top4create.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="type",catalog="top4create_test")
@Searchable
@XmlRootElement
public class Type extends BaseObject implements Serializable {
    private Long id;
    private String tag;
    private String typeName;
    private Set<Company> companies = new HashSet<Company>(0);

    @Id @GeneratedValue(strategy=IDENTITY) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="tag", length=30)
    @SearchableProperty
    public String getTag() {
        return this.tag;
    }
    
    public void setTag(String tag) {
        this.tag = tag;
    }
    
    @Column(name="type_name", length=30)
    @SearchableProperty
    public String getTypeName() {
        return this.typeName;
    }
    
    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="type")
    public Set<Company> getCompanies() {
        return this.companies;
    }
    
    public void setCompanies(Set<Company> companies) {
        this.companies = companies;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Type pojo = (Type) o;

        if (tag != null ? !tag.equals(pojo.tag) : pojo.tag != null) return false;
        if (typeName != null ? !typeName.equals(pojo.typeName) : pojo.typeName != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (tag != null ? tag.hashCode() : 0);
        result = 31 * result + (typeName != null ? typeName.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("tag").append("='").append(getTag()).append("', ");
        sb.append("typeName").append("='").append(getTypeName()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
